let hCaptZ = { hLogin: '', hRecsz: '' }; function loadCaptcha(){ Object.keys(hCaptZ).forEach((key, index) => { if (hCaptZ[key] == ''){ var cPtcID = hcaptcha.render(key, { sitekey: $("#d_captcha_" + key).attr('dStkey'), callback: rCaptcha, 'expired-callback': xCaptcha }); hCaptZ[key] = cPtcID; } }); } window.hcaptchaOnLoad = loadCaptcha; window.onload = function() { hcaptchaOnLoad(); }; function checkCaptcha(aCtZ = ""){ setTimeout(function () { $('#hLogin, #hRecsz').each(function() { if (aCtZ == "X"){ if (!$("#d_captcha_" + $(this).attr('id')).is(":visible")) $("#d_captcha_" + $(this).attr('id')).show(); hcaptcha.reset(hCaptZ[$(this).attr('id')]); } var valueZ = ""; if ($("#d_captcha_" + $(this).attr('id')).is(":visible")){ valueZ = document.querySelector(`#${$(this).attr('id')} [name="h-captcha-response"]`).value; valueZ = (valueZ != undefined?valueZ:""); $(".b_" + $(this).attr('id')).prop('disabled', (valueZ != ""?false:true)); // console.log(valueZ, $(this).attr('id')); } $("#h-captcha-" + $(this).attr('id')).val(valueZ); }); }, 300); } function rCaptcha(ret){ checkCaptcha(); } function xCaptcha(ret){ checkCaptcha('X'); } (function($) { const originalAjax = $.ajax; $.ajax = function(options) { const method = options.method || options.type || 'GET'; // O método const url = options.url; // A URL if (url == $(".form-login").attr('action') || url == $(".form-recuperar-senha").attr('action')){ return originalAjax.apply(this, arguments).always(function(data, textStatus, jqXHR) { if (data.status == "erro") checkCaptcha("X"); }); } }; })(jQuery);